package com.gt.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.gt.common.core.controller.BaseController;
import com.gt.common.core.domain.AjaxResult;
import com.gt.common.core.page.TableDataInfo;
import com.gt.admin.domain.Hospital;
import com.gt.admin.service.IHospitalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 医院Controller
 */
@Api(tags = "sc-医院")
@RestController
@RequestMapping("/hospital")
public class HospitalController extends BaseController {
    @Autowired
    private IHospitalService hospitalService;

    /**
     * 查询全部医院
     * @return
     */
    @ApiOperation("查询全部医院")
    @GetMapping("/lists")
    public TableDataInfo list(){
        startPage();
        LambdaQueryWrapper<Hospital> queryWrapper = new LambdaQueryWrapper<>();
        List<Hospital> list = hospitalService.list(queryWrapper);
        return getDataTable(list);
    }

    /**
     * 根据地市查询医院
     */
    @ApiOperation("根据地市查询医院")
    @GetMapping("/{cityIds}")
    public AjaxResult list(@PathVariable("cityIds") Long[] cityIds){
        LambdaQueryWrapper<Hospital> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.in(Hospital::getCityId, cityIds);
        return AjaxResult.success(hospitalService.list(queryWrapper));
    }

    /**
     * 根据医院名称模糊查询
     */
    @ApiOperation("根据医院名称模糊查询")
    @GetMapping
    public AjaxResult listByName(String name){
        String hName = "%" + name + "%";
        LambdaQueryWrapper<Hospital> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.like(Hospital::getHospitalName, hName);
        return AjaxResult.success(hospitalService.list(queryWrapper));
    }
}
